useTools
The useTools hook provides access to the state of tools and widgets in the Viewer. Tools represent interaction states, such as performing measurements, adding comments, or editing shapes. Widgets, on the other hand, are wrappers for objects in the Viewer that enable custom interactivity, allowing these tools to function effectively. While several built-in tools are available, the system is designed to allow developers to add their own tools and widgets.
Interface: ToolState
The ToolState store is used to register new tools and their supporting UI, as well as to control which tool is currently active.
Properties
activeTool
activeTool: null | string;
The identifier for the currently active tool.
objectWidgets
objectWidgets: object;
A map where scene objects are wrapped in elements to extend the scene at the component level.
Index Signature:
[key: string]: ObjectWidget
toolWindows
toolWindows: object;
A map of tools that can offer a floating bar with custom UI when active.
Index Signature:
[key: string]: ComponentType
Methods
registerObjectWidget
registerObjectWidget: (id: string, widget: ObjectWidget) => void
Adds an ObjectWidget to be rendered as a wrapper for each object in the scene.
- Parameters:
id(string): The identifier for the widget.widget(ObjectWidget): The widget to be registered.
- Returns:
void
removeObjectWidget
removeObjectWidget: (id: string) => void
Removes an ObjectWidget when it is no longer needed. Typically called during unmount.
- Parameters:
id(string): The identifier for the widget to be removed.
- Returns:
void
registerToolWindow
registerToolWindow: (id: string, toolWindow: ComponentType) => void
Registers a ToolWindow for a specified tool name, which is displayed when the tool is active.
- Parameters:
id(string): The identifier for the tool.toolWindow(ComponentType): The component to be registered as the tool window.
- Returns:
void
removeToolWindow
removeToolWindow: (id: string) => void
Removes a ToolWindow component for a tool. Typically called during the unmount of the tool component.
- Parameters:
id(string): The identifier for the tool window to be removed.
- Returns:
void
setActiveTool
setActiveTool: (tool: null | string) => void
Activates the specified tool. Related ObjectWidgets should listen to the activeTool state.
- Parameters:
tool(null | string): The identifier of the tool to activate.
- Returns:
void
The useTools hook is a powerful utility for managing tools and widgets in the Viewer, enabling developers to create custom interactions and extend the functionality of the Viewer. By leveraging the ToolState interface, you can register, manage, and clean up tools and their associated UI components efficiently.